import { stringify } from 'qs';
import request from '@/utils/request';
import { withProcessedData } from '@/utils/marketingMap/utils';

const basePath = '/msmarketingmap/aftersales/outflow';

// 需要删除
// export const fetchMapData = async (query: QueryProps) =>
//   withProcessedData(query, async query => {
//     const result = await request(`${basePath}/map?${stringify(query)}`);

//     if (result.statusCode !== '0') return [];

//     if (!result.data?.code) {
//       message.info('无法获取经销商位置，请稍后再试');
//     }

//     return result.data;
//   });

// 1.专营店流入情况及统计概况
export const fetchOutflowStore = async (query: QueryProps) =>
  withProcessedData(query, async query => {
    const result = await request(`${basePath}/store?${stringify(query)}`);

    if (result.statusCode !== '0') return {};

    return result.data;
  });
// 2.流入趋势图
export const fetchOutflowStoreTrend = async (query: QueryProps) =>
  withProcessedData(query, async query => {
    const result = await request(`${basePath}/store/trend?${stringify(query)}`);

    if (result.statusCode !== '0') return [];

    return result.data;
  });

// 3.流入用户画像-车系分布
export const fetchPersonaSeries = async (query: QueryProps) =>
  withProcessedData(query, async query => {
    const result = await request(`${basePath}/persona/series?${stringify(query)}`);

    if (result.statusCode !== '0') return [];

    return result.data;
  });

// 4.流入用户画像-售后项目分布
export const fetchPersonaProject = async (query: QueryProps) =>
  withProcessedData(query, async query => {
    const result = await request(`${basePath}/persona/project?${stringify(query)}`);

    if (result.statusCode !== '0') return [];

    return result.data;
  });

// 5.流入用户画像-流出收入分布
export const fetchPersonaUserType = async (query: QueryProps) =>
  withProcessedData(query, async query => {
    const result = await request(`${basePath}/persona/income?${stringify(query)}`);

    if (result.statusCode !== '0') return [];

    return result.data;
  });

export const fetchPersonaPortraitInfo = async (query: QueryProps) =>
  withProcessedData(query, async query => {
    const result = await request(
      `/msmarketingmap/aftersales/inflow/persona/portrait/info?${stringify({ ...query, inout: 0, tags: 7 })}`,
    );

    if (result.statusCode !== '0') return [];

    return result.data;
  });

export const fetchPersona = async (query: QueryProps) => {
  return Promise.all([
    fetchPersonaSeries(query),
    fetchPersonaProject(query),
    fetchPersonaUserType(query),
    fetchPersonaPortraitInfo(query)
  ]);
};
